package hy.controller;

import hy.beans.AjaxRestult;
import hy.beans.User;
import hy.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper dao;
    @GetMapping("/login")
    public AjaxRestult login(String name, String pass, HttpSession session){
        System.out.println("name="+name+",pass="+pass);
        User u=dao.selectUserByName(name);
        System.out.println("正确用户："+u);
        AjaxRestult rs=new AjaxRestult();
        if(u!=null&&u.getPass().equals(pass)){
            rs.setSuccess(true);
            session.setAttribute("user",u);
        }
        rs.setData(u);
        return rs;
    }
}